﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Caching;
using Microsoft.Practices.EnterpriseLibrary.Caching.Expirations;

namespace KingSite.Library.Cache.MSCacheWrapper {
    public class MSCacheWrapper : ICache {
        private ICacheManager _manager;

        public MSCacheWrapper() {
            _manager = Microsoft.Practices.EnterpriseLibrary.Caching.CacheFactory.GetCacheManager();
        }

        public void Add(string key, object value) {
            _manager.Add(key, value);
        }

        public void Add(string key, object value, int seconds) {
            _manager.Add(key, value, CacheItemPriority.Normal, null, new SlidingTime(TimeSpan.FromSeconds(seconds)));
        }

        public object Get(string key) {
            return _manager.GetData(key);
        }

        public void Remove(string key) {
            _manager.Remove(key);
        }

        public void Clear() {
            _manager.Flush();
        }
    }
}
